package com.dpj.threadpool;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.util.Timer;
import java.util.TimerTask;

/*
 timer is week,it's serial and it has only one thread,so when the previous work has problem,
 the next work will be affected
 */
@Slf4j(topic = "c.TestTimer")
public class TestTimer {
    public static void main(String[] args) {
        Timer timer=new Timer();
        TimerTask task1 = new TimerTask() {
            @SneakyThrows
            @Override
            public void run() {
                log.debug("task 1");
                Thread.sleep(2000);
            }
        };
        TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                log.debug("task 2");
            }
        };

        log.debug("start");
        timer.schedule(task1,1000);
        timer.schedule(task2,1000);
    }
}
